package com.laoyao.comm.config;

import javax.servlet.http.Cookie;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.laoyao.util.abc;

public class WeixLoginLanjie implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		Cookie cookie = abc.getCookieByName(inv.getController().getRequest(), "token");
		if(cookie!=null){
			System.out.println(cookie.getValue());
			String sql = "select * from user_status where sessionId = ?";
			Record r = Db.findFirst(sql,cookie.getValue());
			
			if(r!=null){
				inv.invoke();
				return;
			}
			
		}
		
		inv.getController().renderJson("needLogin",true);
		
		

	}

}
